-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run fusion property test with arbitrary layouters #96
Conversation
prettyprinter/test/Testsuite/Main.hs
Outdated
instance Arbitrary LayoutOptions where | ||
arbitrary = LayoutOptions <$> oneof | ||
[ AvailablePerLine <$> arbitrary <*> arbitrary | ||
-- , pure Unbounded -- https://github.com/quchen/prettyprinter/issues/91 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I uncomment this, the fusion tests trigger #91:
Shallow fusion does not change rendering: FAIL (0.02s)
*** Failed! (after 56 tests):
Exception:
»SFail« must not appear in a rendered »SimpleDocStream«. This is a bug in the layout algorithm! Please report this as a bug
CallStack (from HasCallStack):
error, called at src/Data/Text/Prettyprint/Doc/Render/Util/Panic.hs:13:21 in prettyprinter-1.5.1-inplace:Data.Text.Prettyprint.Doc.Render.Util.Panic
oakland <(commence inverse)>buttonaccrue tapewormtrackercrowfoot
spheroid ( printer ` ""sailboatbackfieldendorse transit gazelletacticsdrumbeat dogsled dropper puppy dashboard
skydive miser eyeglass apple guidancetonic
oakland southward )
woodlark
minnow
slowdown
<function>
LayoutOptions {layoutPageWidth = Unbounded}
Exception thrown while showing test case:
»SFail« must not appear in a rendered »SimpleDocStream«. This is a bug in the layout algorithm! Please report this as a bug
CallStack (from HasCallStack):
error, called at src/Data/Text/Prettyprint/Doc/Render/Util/Panic.hs:13:21 in prettyprinter-1.5.1-inplace:Data.Text.Prettyprint.Doc.Render.Util.Panic
Use --quickcheck-replay=857723 to reproduce.
Two things could IMHO help analyzing these failures:
-
Shrinking: I wonder whether it might be easiest to just use
hedgehog
instead ofQuickCheck
, since that has built-in shrinking. What do you think about this @quchen? -
A diagnostic representation of the
Doc
(A diagnostic representation for "Doc" #90).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The arabitrary
should be explicit range
s, otherwise you get ribbons of 1e-5 and 2 for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
arabitrary
should be explicitrange
s, otherwise you get ribbons of 1e-5 and 2 for example.
Why would that be a problem? I don't really understand the ribbon width logic so far, but I know that layoutWadlerLeijen
clamps the result to a valid range:
prettyprinter/prettyprinter/src/Data/Text/Prettyprint/Doc/Internal.hs
Lines 1810 to 1814 in 7da3b1d
ribbonWidth = case pWidth of | |
AvailablePerLine lineLength ribbonFraction -> | |
(Just . max 0 . min lineLength . round) | |
(fromIntegral lineLength * ribbonFraction) | |
Unbounded -> Nothing |
I usually try to not to constrain the generated values unless they cause problems – "nonsense" inputs are often helpful at finding bugs in edge cases.
I haven’t used Hedgehog and I’m fairly familiar with Quickcheck, but certainly not opposed to using new technology in order to improve tests. Automatic shrinking does sound cool, I should read up on that! |
92dd87b
to
4cd68f6
Compare
I'd like to build on this in my PRs, so I'll merge soon. Further improvements will hopefully happen as I use these tests. Regarding shrinking: |
Context: #95